# Recipe graphite::install

# Install MySQL
include_recipe "mysql::install"

# Install Graphite
node['graphite']['packages'].each do |pkg|
  package pkg do
    action :install
  end
end

template "/etc/graphite-web/local_settings.py" do
  source "local_settings.py.erb"
  mode 0755
  owner "root"
  group "root"
end

# Configure Mysql for graphite

include_recipe "graphite::mysql"

script "Configure graphite database" do
  interpreter "bash"
  user "root"
  code <<-EOF
    /usr/bin/expect -c 'spawn /usr/lib/python2.6/site-packages/graphite/manage.py syncdb
    expect "Would you like to create one now\? \(yes\/no\)\:"
    send "no\r"
    expect eof'
  EOF
end

service "httpd" do
  action [:enable, :start]
end

service "carbon-cache" do
  action [:enable, :start]
end
